<?php

namespace PlatBundle\Controller;

use ApiBundle\Controller\BaseController;

class MedalController extends BaseController
{
    /*
     * 获取勋章列表
     */
    public function medalListAction()
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAll("SELECT * FROM medal WHERE 1");
        return $this->render("PlatBundle:Medal:index.html.twig",array("data"=>$data));

    }

    /*
     * 编辑/添加勋章
     */

    public function editMedalAction($id)
    {
        if(!$this->get("session")->get("plat_id")){

            return $this->render('PlatBundle:Auth:login.html.twig');
        }

        $conn = $this->get("database_connection");
        $data = $conn->fetchAssoc("SELECT * FROM medal WHERE id = '". $id ."'");

        if(empty($id)){
            $data = array("id" => 0);
        }
        return $this->render("PlatBundle:Medal:edit.html.twig",$data);
    }
}
